import React, { Component } from 'react'
import PropTypes from 'prop-types'

import Def from './Def'

export default class Child extends Component {
  static defaultProps = {
    title: 'defalut value'
  }

  // 定义一个propTypes静态属性
  static propTypes = {
    title: PropTypes.node,
    abc: PropTypes.element,
    def: PropTypes.instanceOf(Def),
    id: PropTypes.oneOf(['001', '002']),
    url: PropTypes.oneOfType([
      PropTypes.string,
      PropTypes.number
    ]),
    list: PropTypes.arrayOf(PropTypes.string),
    obj1: PropTypes.shape({
      x: PropTypes.number,
      y: PropTypes.string.isRequired
    }),
    obj2: PropTypes.exact({
      x: PropTypes.number,
      y: PropTypes.string.isRequired
    }),
    count(props, propName, componentName) {
      console.log(props, propName, componentName)
      if (props[propName] <= 100) {
        throw new Error('error')
      }
    }
  }

  render() {
    // let Abc = this.props.abc
    return (
      <div>
        {this.props.title}
        {this.props.abc}
        {this.props.id}<br></br>
        {this.props.url}<br></br>
        {this.props.list}<br></br>
        {this.props.obj1.x}
      </div>
    )
  }
}

// Child.defaultProps = {
//   title: 'defalut value'
// }